/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testsortedmap;

import java.util.Random;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 *
 * @author hitdong
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        SortedMap<Person, Integer> map = new TreeMap<Person, Integer>(new PersonComparator());
        Person one = new Person("one", new Random().nextInt(1000));
        Person two = new Person("two", new Random().nextInt(1000));
        Person three = new Person("three", new Random().nextInt(1000));
        Person four = new Person("four", new Random().nextInt(1000));
        map.put(one, one.getWealth());
        map.put(two, two.getWealth());
        map.put(three, three.getWealth());
        map.put(four, four.getWealth());
        for (Person person : map.keySet()) {
            System.out.println(person.getName()+" : "+person.getWealth());
        }
        Person first = map.firstKey();
        System.out.println("---------------\n");
        System.out.println(first.getName()+" : "+first.getWealth());
        Person last = map.lastKey();
        System.out.println(last.getName()+" : "+last.getWealth());
        
    }
}
